﻿using AutoMapper;
using NetTaste;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using VM.Common.Result;
using VM.Entity.EntityDto.Goods;
using VM.Entity.EntityMap.Goods;
using VM.Entity.EntityMap.ICon;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Menu;
using VM.Entity.EntityMap.System.Code;
using VM.Entity.EntityMap.Topic;
using VM.IDAL.Goods;

namespace VM.DAL.Goods
{
    public class GoodsTypeDAL : BaseDAL, IGoodsTypeDAL
    {

        protected ISqlSugarClient _Client { get; set; }
        protected IMapper _IMapper { get; set; }

        public GoodsTypeDAL(ISqlSugarClient client, IMapper iMapper) : base(client)
        {
            _Client = client;
            _IMapper = iMapper;
        }

        public PagingData<getGoodsTypeListDto> getGoodsTypeList(string? name, int? userId, int pageSize, int pageIndex)
        {
            var ListRes = _Client.Queryable<getGoodsTypeListDto>()
                         .Includes(a => a.createUser)
                         .Includes(a => a.updateUser)
                         .WhereIF(name != null && name != "", a => a.name.Contains(name))
                         .OrderBy(a => a.id);

            PagingData<getGoodsTypeListDto> result = new PagingData<getGoodsTypeListDto>()
            {
                dataList = ListRes.ToPageList(pageIndex, pageSize),
                pageIndex = pageIndex,
                pageSize = pageSize,
                recordCount = ListRes.Count(),
                searchString = name
            };

            return result;

        }

        public int addGoodsType(sys_goodsType obj)
        {
            int Res = _Client.Insertable(obj).ExecuteCommand();
            return Res;
        }
    }
}
